package com.scsj.cloud.hdata.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.scsj.cloud.base.rest.RestResponse;
import com.scsj.cloud.hdata.service.HDFSService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @D 对HDFS的操作
 * @author caoxiubin
 */
@RestController
@RequestMapping("/scsj/hadoop/hdfs")
@Api(value = "HDFS相关")
public class HDFSController {
	
	@Autowired
	private HDFSService hDFSService;
	
 
	@GetMapping("/mkdir")
    @ApiOperation(value = "创建文件目录", notes = "参数：目录路劲")
    public RestResponse mkdir(@RequestParam("path") String path) throws Exception {
    	return hDFSService.mkdir(path);
    }
    
    @PostMapping("/createFile")
    @ApiOperation(value = "创建文件", notes = "参数：文件路劲")
    public RestResponse createFile(@RequestParam("path") String path, 
    		@RequestParam("file") MultipartFile file) throws Exception {
    	return hDFSService.createFile(path, file);
    }
    
    @GetMapping("/readFile")
    @ApiOperation(value = "读取文件", notes = "参数：文件路劲")
    public RestResponse readFile(@RequestParam("path") String path) throws Exception {
    	return hDFSService.readFile(path);
    }
    
    @GetMapping("/listDir")
    @ApiOperation(value = "展示所有文件目录", notes = "参数：需要展示目录路劲")
    public RestResponse readPathInfo(@RequestParam("path") String path) throws Exception {
    	return hDFSService.readPathInfo(path);
    }
    
    @GetMapping("/listFile")
    @ApiOperation(value = "展示所有文件", notes = "参数：需要展示文件路劲")
    public RestResponse listFile(@RequestParam("path") String path) throws Exception {
    	return hDFSService.listFile(path);
    }
    
    @PostMapping("/renameFile")
    @ApiOperation(value = "重命名文件", notes = "参数：旧文件名和新文件名")
    public RestResponse renameFile(@RequestParam("oldName") String oldName, 
    		@RequestParam("newName") String newName) throws Exception {
    	return hDFSService.renameFile(oldName, newName);
    }
    
    @DeleteMapping("/deleteFile")
    @ApiOperation(value = "删除文件", notes = "参数：需要删除文件路径")
    public RestResponse deleteFile(@RequestParam("path") String path) throws Exception {
    	return hDFSService.deleteFile(path);
    }
    
    @PostMapping("/uploadFile")
    @ApiOperation(value = "上传文件", notes = "参数：上传路径和目标路径")
    public RestResponse uploadFile(@RequestParam("path") String path, 
    		@RequestParam("uploadPath") String uploadPath) throws Exception {
    	return hDFSService.uploadFile(path, uploadPath);
    }
    
    @GetMapping("/downloadFile")
    @ApiOperation(value = "下载文件", notes = "参数：下载路径和目标路径")
    public RestResponse downloadFile(@RequestParam("path") String path, 
    		@RequestParam("downloadPath") String downloadPath) throws Exception {
    	return hDFSService.downloadFile(path, downloadPath);
    }
    
    @GetMapping("/copyFile")
    @ApiOperation(value = "复制文件", notes = "参数：原始文件路径和目标路径")
    public RestResponse copyFile(@RequestParam("sourcePath") String sourcePath, 
    		@RequestParam("targetPath") String targetPath) throws Exception {
    	return hDFSService.copyFile(sourcePath, targetPath);
    }
    
    
}
